package countPrimeSetBits;

public class Solution {
    public int countPrimeSetBits(int left, int right) {
        int count=0;
        for (int i = left; i <=right ; i++) {
            if(isZhi(getNum(i))){
                System.out.println(i);
               count++;
            }
        }
        return count;
    }
    private static int getNum(int n){
        int count=0;
        while(n!=0){
            n=n&(n-1); //消去最右边的1
            count++;
        }
        return count;
    }
    private boolean isZhi(int n){
        int k=(int)Math.sqrt(n);
        for (int i = 2; i <=k ; i++) {
            if(n%i==0){
                return false;
            }
        }
        return true;
    }
}
